package view;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.table.TableColumnModel;
import javax.swing.SwingConstants;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import controleOperacao.ModelControleOperacao;



public class OperacaoJanela extends JFrame {

	private static final long serialVersionUID = 1L;
	
	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="25,19"
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	
	private JButton jButtonSalvar = null;
	private JButton jButtonCancelar = null;
	private JButton jButtonExcluir = null;
	private JButton jButtonImprimir = null;
	
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	ModelControleOperacao modelControleOperacao = null;
	
	private JLabel jLabelCliente = null;
	private JLabel jLabelBanco = null;
	private JLabel jLabelValorCheque = null;
	private JLabel jLabelDataCheque = null;
	private JLabel jLabelJuros = null;
	private JLabel jLabelRepasse = null;
	private JLabel jLabelTitulo = null;
	
	private JTextField jTextFieldRepasse = null;
	private JTextField jTextFieldJuros = null;
	private JTextField jTextFieldValorCheque = null;
	private JTextField jTextFieldDataCheque = null;
	private JTextField jTextFieldDias = null;
	
	private JList jListBanco = null;
	private JList jListCliente = null;
	
	private JMenuBar jJMenuBar = null;
	private JMenu jMenu = null;
	private JMenuItem jMenuItem = null;

	private JLabel jLabelDias;
	
	
	public void criarJanela(ModelControleOperacao modelControleOperacao){
		//super.initialize(700, 630);
		this.modelControleOperacao = modelControleOperacao;
		getJFrame();
		jFrame.setVisible(true);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	/*************************************************************************/
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setSize(new Dimension(773, 505));
			jFrame.setJMenuBar(getJJMenuBar());
			jFrame.setContentPane(getJContentPane());
		}
		return jFrame;
	}

	/*************************************************************************/
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJScrollPane(), null);
			jContentPane.add(getJPanel2(), null);
			jContentPane.add(getJMenu(), null);
		}
		return jContentPane;
	}


	/*************************************************************************/
	private JButton getJButtonSalvar() {
		if (jButtonSalvar == null) {
			jButtonSalvar = new JButton();
			jButtonSalvar.setText("Salvar");
			jButtonSalvar.setBounds(new Rectangle(455, 196, 95, 30));
		}
		return jButtonSalvar;
	}

	/*************************************************************************/
	
	private JButton getJButtonCancelar() {
		if (jButtonCancelar == null) {
			jButtonCancelar = new JButton();
			jButtonCancelar.setText("Cancelar");
			jButtonCancelar.setBounds(new Rectangle(549, 196, 95, 30));
		}
		return jButtonCancelar;
	}

	/*************************************************************************/
	
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(7, 250, 748, 200));
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/*************************************************************************/
	
	public JTable getJTable() {
		if (jTable == null) {
			jTable = new JTable();
		}
		return jTable;
	}

	/*************************************************************************/
	
	public JButton getJButtonExcluir() {
		if (jButtonExcluir == null) {
			jButtonExcluir = new JButton("Excluir");
			jButtonExcluir.setBounds(new Rectangle(361, 196, 95, 30));
		}
		return jButtonExcluir;
	}

	/*************************************************************************/
	
	private JButton getJButtonImprimir() {
		if (jButtonImprimir == null) {
			jButtonImprimir = new JButton("Imprimir");
			jButtonImprimir.setBounds(new Rectangle(644, 196, 95, 30));
		}
		return jButtonImprimir;
	}

	/*************************************************************************/
	
	private JPanel getJPanel2() {
		if (jPanel == null) {
			
			
			jLabelTitulo = new JLabel();
			jLabelTitulo.setBounds(new Rectangle(5, 3, 342, 22));
			jLabelTitulo.setText("OPERAÇÃO CHEQUE");
			
			jLabelRepasse = new JLabel();
			jLabelRepasse.setBounds(new Rectangle(230, 163, 63, 20));
			jLabelRepasse.setText("Repasse:"); 

			jLabelJuros = new JLabel();
			jLabelJuros.setBounds(new Rectangle(6, 163, 109, 20));
			jLabelJuros.setHorizontalTextPosition(SwingConstants.RIGHT);
			jLabelJuros.setText("Juros:"); 
			
			jLabelDias = new JLabel();
			jLabelDias.setBounds(new Rectangle(6, 138, 109, 20));
			jLabelDias.setHorizontalTextPosition(SwingConstants.RIGHT);
			jLabelDias.setText("Dias:"); 
			
			jLabelDataCheque = new JLabel();
			jLabelDataCheque.setBounds(new Rectangle(6, 113, 109, 20));
			jLabelDataCheque.setText("Data Cheque:"); 
			
			jLabelValorCheque = new JLabel();
			jLabelValorCheque.setBounds(new Rectangle(6, 88, 109, 20));
			jLabelValorCheque.setText("* Valor Cheque:");
			
			jLabelBanco = new JLabel();
			jLabelBanco.setBounds(new Rectangle(6, 63, 109, 20));
			jLabelBanco.setHorizontalTextPosition(SwingConstants.LEFT);
			jLabelBanco.setText("* Banco:");
			
			jLabelCliente = new JLabel();
			jLabelCliente.setBounds(new Rectangle(6, 38, 109, 20));
			jLabelCliente.setHorizontalTextPosition(SwingConstants.LEFT);
			jLabelCliente.setText("* Cliente:");
			
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(7, 8, 748, 235));
			jPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			
			jPanel.add(jLabelCliente, null);
			jPanel.add(jLabelBanco, null);
			jPanel.add(jLabelValorCheque, null);
			jPanel.add(jLabelTitulo, null);
			jPanel.add(jLabelDias, null);
			jPanel.add(jLabelDataCheque, null);
			jPanel.add(jLabelJuros, null);
			jPanel.add(jLabelRepasse, null);
			
			jPanel.add(getJTextFieldRepasse(), null);
			jPanel.add(getJTextFieldJuros(), null);
			jPanel.add(getJTextFieldValorCheque(), null);
			jPanel.add(getJListBanco(), null);
			jPanel.add(getJTextFieldDataCheque(), null);
			jPanel.add(getJTextFieldDias(), null);
			jPanel.add(getJList(), null);
			jPanel.add(getJButtonSalvar(), null);
			jPanel.add(getJButtonImprimir(), null);
			jPanel.add(getJButtonCancelar(), null);
			jPanel.add(getJButtonExcluir(), null);
		}
		return jPanel;
	}

	/*************************************************************************/
	
	private JTextField getJTextFieldRepasse() {
		if (jTextFieldRepasse == null) {
			jTextFieldRepasse = new JTextField();
			jTextFieldRepasse.setBounds(new Rectangle(300, 165, 92, 20));
		}
		return jTextFieldRepasse;
	}

	/*************************************************************************/
	
	private JTextField getJTextFieldJuros() {
		if (jTextFieldJuros == null) {
			jTextFieldJuros = new JTextField();
			jTextFieldJuros.setBounds(new Rectangle(123, 163, 86, 20));
		}
		return jTextFieldJuros;
	}

	/*************************************************************************/
	
	private JTextField getJTextFieldValorCheque() {
		if (jTextFieldValorCheque == null) {
			jTextFieldValorCheque = new JTextField();
			jTextFieldValorCheque.setBounds(new Rectangle(123, 88, 86, 20));
		}
		return jTextFieldValorCheque;
	}

	/*************************************************************************/
	
	private JList getJListBanco() {
		if (jListBanco == null) {
			jListBanco = new JList();
			jListBanco.setBounds(new Rectangle(123, 63, 434, 20)); 
		}
		return jListBanco;
	}

	/*************************************************************************/
	
	private JTextField getJTextFieldDataCheque() {
		if (jTextFieldDataCheque == null) {
			jTextFieldDataCheque = new JTextField();
			jTextFieldDataCheque.setBounds(new Rectangle(123, 113, 106, 20));
		}
		return jTextFieldDataCheque;
	}

	/*************************************************************************/
	
	private JTextField getJTextFieldDias() {
		if (jTextFieldDias == null) {
			jTextFieldDias = new JTextField();
			jTextFieldDias.setBounds(new Rectangle(123, 138, 86, 20));
		}
		return jTextFieldDias;
	}

	/*************************************************************************/
	
	private JList getJList() {
		if (jListCliente == null) {
			jListCliente = new JList();
			jListCliente.setBounds(new Rectangle(123, 38, 508, 20));
		}
		return jListCliente;
	}

	/*************************************************************************/
	
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getJMenu());
		}
		return jJMenuBar;
	}

	/*************************************************************************/
	
	private JMenu getJMenu() {
		if (jMenu == null) {
			jMenu = new JMenu();
			jMenu.setBounds(new Rectangle(22, 7, 85, 19));
			jMenu.setText("Arquivo");
			jMenu.add(getJMenuItem());
		}
		return jMenu;
	}

	/*************************************************************************/
	
	private JMenuItem getJMenuItem() {
		if (jMenuItem == null) {
			jMenuItem = new JMenuItem();
			jMenuItem.setText("que");
		}
		return jMenuItem;
	}
	/*fim do jframe*/
	
	/*************************************************************************/
	/*************************************************************************/
	
	public static void main(String args[]){
		OperacaoJanela Janela = new OperacaoJanela();
		Janela.setVisible(true);
		Janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void setListenerBotaoSalvar(ActionListener listener) {
		getJButtonSalvar().addActionListener(listener);
		
	}

	public void setListenerBotaoCancelar(ActionListener listener) {
		getJButtonCancelar().addActionListener(listener);	
		
	}

	public void setListenerBotaoExcluir(ActionListener listener) {
		getJButtonExcluir().addActionListener(listener);	
		
	}

	public void setListenerCliqueDuplo(MouseAdapter evt) {
		getJTable().addMouseListener(evt);
		
	}

	public void setListenerSoNumero(FocusListener listener) {
		// TODO Auto-generated method stub
		
	}
	
	public void escondeColID(int col){
		TableColumnModel  colunaModelo = getJTable().getColumnModel();      
		colunaModelo.getColumn(col).setMinWidth(0);     
		colunaModelo.getColumn(col).setPreferredWidth(0);  
		colunaModelo.getColumn(col).setMaxWidth(0); 	
	}
	
	public void limparFormulario(){
		getJTextFieldDataCheque().setText("");
		getJTextFieldDias().setText("");
		getJTextFieldJuros().setText("");
		getJTextFieldRepasse().setText("");
		getJTextFieldValorCheque().setText("");

	}
	public void preencheFormulario(Object object){
		/*getJTextFieldCep().setText(cliente.getCep());
		getJTextFieldCelular().setText(cliente.getCelular());
		getJTextFieldBairro().setText(cliente.getBairro());
		getJTextFieldCnpf().setText(cliente.getCpf_cnpj());
		getJTextFieldContato().setText(cliente.getContato());
		getJTextFieldEmail().setText(cliente.getEmail());
		getJTextFieldEndereco().setText(cliente.getLougradoro());
		getJTextFieldFax().setText(cliente.getFax());
		getJTextFieldMunicipio().setText(cliente.getMunicipio());
		getJTextFieldRg().setText(cliente.getIe_rg());
		getJTextFieldTelefone().setText(cliente.getTelefone());
		getJTextFieldNome().setText(cliente.getNome());
		
		int tam = getJComboBoxUf().getItemCount();
		for(int i = 0; i < tam; i ++){
			if(((Estado)getJComboBoxUf().getItemAt(i)).getId() == cliente.getIdEstado()){
				getJComboBoxUf().setSelectedIndex(i);
				break;
			}
		}*/
		
	}
}
